home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI303.ASC < prev    next >
Text File  |  1991-09-11  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.   PRODUCT : TURBO PASCAL                               NUMBER : 303
  10.   VERSION : ALL
  11.        OS : PC-DOS
  12.      DATE : May 21, 1986                                 PAGE : 1/4
  13.     TITLE : DIRECT VIDEO ADDRESSING
  14.  
  15.  
  16.  
  17.  
  18.   Using Mem and MemW you may address any location on the screen and
  19.   change  its  value.  A  possible  use might be creating a  memory
  20.   mapped text editor. The  following  in an example of using Mem to
  21.   address the text screen one byte at a time. (Exchange $B800   for
  22.   $B000 if you have a monochrome screen.)
  23.  
  24.   program RAM2;
  25.  
  26.   Var
  27.     j, i : integer;
  28.     ch : char;
  29.  
  30.   begin
  31.     j := 0;
  32.     for i := 1 to 2048 do
  33.     begin
  34.       Mem[$B800:j] := $80;                    {Accessing video RAM
  35.       Mem[$B800:j + 1] := $99                  a byte at a time}
  36.     j := j + 2
  37.     end;
  38.   end.
  39.  
  40.   When accessing RAM addressing a word at a time  using  MemW,  you
  41.   must be aware of the following:
  42.  
  43.   1.   In text mode, when you enter a word value, it is broken down
  44.        into two bytes which are placed on the screen. Consequently,
  45.        word values must equal the sum of two bytes  that  you  want
  46.        sent consecutively to the screen.
  47.   2.   You must first assign the low byte, then the  high  byte  of
  48.        the word.
  49.   3.   You must increase the offset by two to access  the next word
  50.        in memory.
  51.  
  52.   MemArray
  53.   program RAM1;
  54.  
  55.   Var
  56.     j, i : integer;
  57.   begin
  58.     j := 0;
  59.     for i := 1 to 2048 do
  60.     begin
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.   PRODUCT : TURBO PASCAL                               NUMBER : 303
  76.   VERSION : ALL
  77.        OS : PC-DOS
  78.      DATE : May 21, 1986                                 PAGE : 2/4
  79.     TITLE : DIRECT VIDEO ADDRESSING
  80.  
  81.  
  82.  
  83.  
  84.       MemW[$B800:j] := $9908;          { Accessing video RAM a word
  85.                                          at a time }
  86.       j := j + 2;
  87.     end;
  88.   end.
  89.  
  90.   The following  program  demonstrates  how  to  write  directly to
  91.   screen memory and  save  and restore text screens. These routines
  92.   may cause snow on some monitors. There are routines in the Editor
  93.   Toolbox to read and write to the screen without  snow,  but  they
  94.   are much harder to use and less intuitive than these ones.
  95.  
  96.   program ScreenTest;
  97.   type                 { Row, Column }
  98.     ScreenType = array [1..25, 1..80] of record
  99.       Character : Char;
  100.       Attribute : Byte;
  101.     end;
  102.  
  103.     AnyString = string [80];    { Generic string type }
  104.  
  105.   { The attribute byte of this data structure is formatted as
  106.   follows:
  107.  
  108.   Bits 0-3 hold the foreground  color, bits 4-6 hold the background
  109.   color, and bit 7 indicates whether blinking is on or off.
  110.  
  111.   Bit                  0     1     2     3    4     5     6      7
  112.   Color Part           FG    FG    FG    FG   BG    BG    BG     BL
  113.   Color Part Value     1     2     4     8    1     2     4      1
  114.   Bit Value (Decimal)  1     2     4     8    16    32    64     128
  115.   Bit Value (Hex)    $01   $02   $04   $08   $10   $20   $40     $80 }
  116.  
  117.   var
  118.     ColorScreen : ScreenType absolute $B800:0;
  119.                                { Use for color screen }
  120.     MonoScreen : ScreenType absolute $B000:0;
  121.                                { Use for monochrome screen }
  122.     SavedScreen : ScreenType;
  123.                                { Buffer to save the screen }
  124.  
  125.   function MakeAttribute(Foreground, Background : Byte;
  126.                          Blink : Boolean) : Byte;
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.   PRODUCT : TURBO PASCAL                               NUMBER : 303
  142.   VERSION : ALL
  143.        OS : PC-DOS
  144.      DATE : May 21, 1986                                 PAGE : 3/4
  145.     TITLE : DIRECT VIDEO ADDRESSING
  146.  
  147.  
  148.  
  149.  
  150.   {  Creates  an  attribute  byte  from  a  combination  of  foreground,
  151.   background, and blinking attributes }
  152.  
  153.   begin
  154.      MakeAttribute := Foreground + (Background shl 4) +
  155.                      (Ord(Blink) shl 7);
  156.   end; { MakeAttribute }
  157.  
  158.   procedure WriteString(S : AnyString; var Screen : ScreenType;
  159.                         Col, Row, Attrib : Byte);
  160.  
  161.   { Writes a string into screen memory starting at a particular row  and
  162.   column, using Attrib as the color attribute. }
  163.  
  164.   var
  165.     Counter : Byte;
  166.  
  167.   begin
  168.     for Counter := 1 to Length(S) do
  169.     begin
  170.       Screen[Row, Pred(Col + Counter)].Character := S[Counter];
  171.       Screen[Row, Pred(Col + Counter)].Attribute := Attrib;
  172.     end;
  173.   end; { WriteString }
  174.  
  175.   begin
  176.     SavedScreen := ColorScreen;     { Save the current screen }
  177.     Window(25, 5, 55, 15);          { Create the new window }
  178.     GotoXY(1, 1);                   { Move inside the new window }
  179.     TextColor(Yellow);              { Change the current colors }
  180.     TextBackground(Red);
  181.     ClrScr;
  182.  
  183.                     { Clear the window and fill it with color }
  184.     WriteString('  Press Return to continue...', ColorScreen, 25, 5,
  185.                 MakeAttribute(Yellow, Red, False));
  186.                 { Write out prompt - note that WriteString uses the
  187.                   absolute  row and column,  not the row and column
  188.                   of the current window }
  189.     Read;                           { Wait for return to be pressed }
  190.     ColorScreen := SavedScreen;     { Restore old screen }
  191.   end.
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.